-
Notifications
You must be signed in to change notification settings - Fork 3k
Add Deep Links #10834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Deep Links #10834
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-pypi-previews.s3.amazonaws.com/25a2f4726cb993970e7353b0ae4d8e4ca02fdc99/gradio-5.22.0-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@25a2f4726cb993970e7353b0ae4d8e4ca02fdc99#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-npm-previews.s3.amazonaws.com/25a2f4726cb993970e7353b0ae4d8e4ca02fdc99/gradio-client-1.13.1.tgz Use Lite from this PR <script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/25a2f4726cb993970e7353b0ae4d8e4ca02fdc99/dist/lite.js""></script> |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
@freddyaboulton What are your thoughts on adding the "share" button to the footer in a little dropdown? Something like this? Only downside is it would be kinda tucked away. |
I felt that a button would maximize visibility. But open to adding it to the share menu in addition once that's in |
@freddyaboulton Makes sense! |
Sweet @freddyaboulton! Testing it right now, a few suggestions in the meantime:
![]()
|
One issue I noticed while testing was that it does not seem to work in reload mode? For repro, my import gradio as gr
def welcome(name):
return f"Welcome to Gradio, {name}!"
with gr.Blocks() as demo:
gr.Markdown(
"""
# Hello World!
Start typing below to see the output.
""")
inp = gr.Textbox(placeholder="What is your name?")
out = gr.Textbox()
inp.change(welcome, inp, out)
gr.DeepLinkButton()
if __name__ == "__main__":
demo.launch() and when I ran |
Otherwise works great in a variety of demos that I tested with & the UX is fantastic. Great work @freddyaboulton! |
Oh one more thing, I tested on Spaces: https://abidlabs-chatbot-streaming-test.hf.space/ and while the generated link technically works: https://abidlabs-chatbot-streaming-test.hf.space/?__theme=system&deep_link=98QjNSX0-NI, it uses the embedded app url instead of the Space URL. I think it would be nicer if it could use the Space URL if on Spaces, since that also works: https://huggingface.co/spaces/abidlabs/chatbot_streaming_test?deep_link=98QjNSX0-NI |
Actually ignore this, the way you have it right now is better in case there are multiple Space replicas. In that case, the state of the app will be serialized to a specific replica, which will be identifiable by the root URL |
Sounds good @abidlabs ! Thanks |
* changes * add changeset * type * add changeset --------- Co-authored-by: gradio-pr-bot <[email protected]>
…xt (#10814) * changes * add changeset * format' * test * copy * changes * doc * format --------- Co-authored-by: gradio-pr-bot <[email protected]>
* changes * add changeset --------- Co-authored-by: Ali Abid <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]>
* remove editable condition * - add test - improve html semantics * add changeset * fix test * fix test * - fix test - fix column widths changing on sort * swap e2e for story --------- Co-authored-by: gradio-pr-bot <[email protected]>
* changes * changes * add changeset * changes * changes * changes * changes * changes * changes * changes --------- Co-authored-by: Ali Abid <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Abubakar Abid <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
hi @abidlabs ! thanks for the thoughtful review.
Not currently possible with how svgs are embedded in buttons via the python class. The right way to do this would be to have the svg color match the
Fixed
Done!
I started doing this but then I realized that the demos on the website run on gradio-lite so the button wouldn't actually work. Let's leave gradio-lite compatibility for a separate PR if we really want to support it.
Done! |
@@ -53,6 +54,18 @@ After you have [created a free Hugging Face account](https://huggingface.co/join | |||
<source src="https://github.com/gradio-app/gradio/blob/main/guides/assets/hf_demo.mp4?raw=true" type="video/mp4" /> | |||
</video> | |||
|
|||
## Sharing Deep Links | |||
|
|||
You can add a button to your Gradio app that creates a unique URL you can use to share your app **as it currently is** with others. This is useful for sharing unique and interesting generations from your application , or for saving a snapshot of your app at a particular point in time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add a button to your Gradio app that creates a unique URL you can use to share your app **as it currently is** with others. This is useful for sharing unique and interesting generations from your application , or for saving a snapshot of your app at a particular point in time. | |
You can add a button to your Gradio app that creates a unique URL you can use to share your app and all components **as they currently are** with others. This is useful for sharing interesting generations from your application or for saving a snapshot of your app at a particular point in time. |
$code_deep_link | ||
$demo_deep_link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this demo was pushed (which might also be why the CI is failing)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea good call!
gradio/interface.py
Outdated
@@ -144,6 +145,7 @@ def __init__( | |||
| None = None, | |||
time_limit: int | None = 30, | |||
stream_every: float = 0.5, | |||
deep_link: str | DeepLinkButton | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add docstring for this param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, as it's currently implemented, there's no way for users to disable the deep link for their Gradio app on Spaces. I think we should allow this, for example if a user sets deep_link=False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if I want to "just enable it" in my Interface running locally, I should be able to set deep_link=True
without having to provide a str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM great PR @freddyaboulton!
I noticed one other issue, which is that if you launch a Gradio app and click on the deep link button before any other events, then you get an invalid deep link (e.g. http://127.0.0.1:7865/?deep_link=Error). We should handle this case. But otherwise, all of the issues I identified are resolved!
Thank you for the review @abidlabs! |
Very cool @freddyaboulton! Feel like we should replace the flag button with the deep link button on Interfaces on Spaces |
That’s exactly what happens @aliabid94 (flagging is disabled, share links are enabled on Spaces) |
Description
Closes: #2269
Adds
gr.DeepLinkButton
- a button that snapshots the current state of the app and generates a short link that points to that snapshot. The deep links are of the form<app-url>?deep_link=<short-hash>
and are automatically copied to the clipboard for easy sharing.Under the hood:
StateHolder
. This should be a minimal increase in server memory usage since we're already storing all other props in theStateHolder
and the serialized value is small since it's serialized.Sharing Image Gen
Sharing chatbot
Sharing Render
Invalid Share Link UX
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Testing and Formatting Your Code
PRs will only be merged if tests pass on CI. We recommend at least running the backend tests locally, please set up your Gradio environment locally and run the backed tests:
bash scripts/run_backend_tests.sh
Please run these bash scripts to automatically format your code:
bash scripts/format_backend.sh
, and (if you made any changes to non-Python files)bash scripts/format_frontend.sh